using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace Soyuz5.Utility.Windows.Forms
{
    public static class FormControl
    {
        /// <summary>
        /// Find control by id
        /// </summary>
        /// <param name="control"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void EnableControlTree(Control control, bool enabled)
        {
            control.Enabled = enabled;
            foreach (Control child in control.Controls)
            {
                EnableControlTree(child, enabled);
            }
        }

        /// <summary>
        /// Find control by id
        /// </summary>
        /// <param name="control"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static void EnableControlTree(ToolStripMenuItem control, bool enabled)
        {
            control.Enabled = enabled;
            foreach (ToolStripItem child in control.DropDownItems)
            {
                if (child is ToolStripMenuItem)
                    EnableControlTree((ToolStripMenuItem)child, enabled);
            }
        }
    }
}
